<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUser extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
     public function up()
    {
        // 创建
        // Schema::create('users', function (Blueprint $table) {
        //     $table->increments('id');
        //     $table->string('username');
        //     $table->string('password');
        //     $table->string('img')->comment('头像');
        //     $table->string('email')->comment('邮箱');
        //     $table->tinyInteger('age')->unsigned();
        //     $table->tinyInteger('test')->unsigned();
        //     $table->timestamps();
        // });
        // 
        if (!Schema::hasTable('users')) {
            # code...
            // 创建
            Schema::create('users', function (Blueprint $table) {
                $table->increments('id');
                $table->string('username');
                $table->string('password');
                $table->string('img')->comment('头像');
                $table->string('email')->comment('邮箱');
                $table->tinyInteger('age')->unsigned();
                $table->tinyInteger('test')->unsigned();
                $table->timestamps();
            });
        } else {
            Schema::table('users', function ($table) {
                if (!Schema::hasColumn('users', 'b')) {
                    # code...
                    $table -> string('b');
                }

                if (!Schema::hasColumn('users', 'c')) {
                    # code...
                    $table -> string('c');
                }

                // 检测 $table -> dropcolumn('votes');
                if (Schema::hasColumn('users', 'b')) {
                    # code...
                    $table -> dropcolumn('b');
                }
                if (Schema::hasColumn('users', 'c')) {
                    # code...
                    $table -> dropcolumn('c');
                }
                if (Schema::hasColumn('users', 'test')) {
                    # code...
                    $table -> dropcolumn('test');
                }
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
         Schema::drop('users');
    }
}
